api.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 17
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 1
rs 10
c 17
b 0
f 0
1
/**
2
 * Client SDK for using server's APIs
3
 *
4
 * @since 1.0.0
5
 */
6
7
const Axios = require('axios');
8
const config = require('../config/server.config');
9
const util = require('./common-util');
10
11
const axios = Axios.create({
12
  baseURL: config.url.apiPrefix,
13
  transformRequest: [data => JSON.stringify(util.camel2snakeObject(data))],
14
  transformResponse: [data => util.snake2camelObject(JSON.parse(data))],
15
});
16
axios.defaults.headers.post['Content-Type'] = 'application/json';
17
axios.defaults.headers.put['Content-Type'] = 'application/json';
18
19
/**
20
 * Try to login
21
 * @param {Object} data
22
 *    - {string} username
23
 *    - {string} password
24
 */
25
exports.login = data => axios.post('/login', data);
26
27
/**
28
 *
29
 * @param data
30
 */
31
exports.changePassword = data => axios.put('/passwords', data);
32
33
/**
34
 * Get status(notification) list
35
 * @param {string} filter - filter name: 'current' or 'expired'
36
 * @param {number} skip - numbers of records to be skipped
37
 * @param {number} limit - numbers of records to be returned
38
 */
39
exports.getStatus = (filter, skip, limit) => axios.get('/status', { params: { filter, skip, limit } });
40
41
/**
42
 * Add a status(notification)
43
 * @param {Object} data
44
 *    - {string} type
45
 *    - {Array} deviceTypes
46
 *    - {string} startTime (ISO 8601 format)
47
 *    - {string} endTime (ISO 8601 format)
48
 *    - {string} contents
49
 *    - {boolean} isActivated
50
 *    - {string} deviceSemVersion
51
 *    - {string} appSemVersion
52
 */
53
exports.addStatus = data => axios.post('/status', data);
54
55
/**
56
 * Update a status(notification)
57
 * @param {string} statusId
58
 * @param {Object} data
59
 *    - {string} type
60
 *    - {Array} deviceTypes
61
 *    - {string} startTime (ISO 8601 format)
62
 *    - {string} endTime (ISO 8601 format)
63
 *    - {string} contents
64
 *    - {boolean} isActivated
65
 *    - {string} deviceSemVersion
66
 *    - {string} appSemVersion
67
 */
68
exports.updateStatus = (statusId, data) => axios.put(`/status/${statusId}`, data);
69
70
/**
71
 * Remove a status(notification)
72
 * @param {string} statusId
73
 */
74
exports.removeStatus = statusId => axios.delete(`/status/${statusId}`);
75
76
/**
77
 * Activate a status(notification)
78
 * @param {string} statusId
79
 */
80
exports.activateStatus = statusId => axios.put(`/status/${statusId}/activate`);
81
82
/**
83
 * Deactivate a status(notification)
84
 * @param {string} statusId
85
 */
86
exports.deactivateStatus = statusId => axios.put(`/status/${statusId}/deactivate`);
87
88
/**
89
 * Get status type list
90
 */
91
exports.getStatusTypes = () => axios.get('/status-types');
92
93
/**
94
 * Add a status type
95
 * @param {Object} data
96
 *    - {string} label
97
 *    - {string} value
98
 *    - {string} template
99
 */
100
exports.addStatusType = data => axios.post('/status-types', data);
101
102
/**
103
 * Update a status type
104
 * @param {string} statusTypeId
105
 * @param {Object} data
106
 *    - {string} label
107
 *    - {string} value
108
 *    - {string} template
109
 */
110
exports.updateStatusType = (statusTypeId, data) => axios.put(`/status-types/${statusTypeId}`, data);
111
112
/**
113
 * Remove a status type
114
 * @param {string} statusTypeId
115
 */
116
exports.removeStatusType = statusTypeId => axios.delete(`/status-types/${statusTypeId}`);
117
118
/**
119
 * Get device type list
120
 */
121
exports.getDeviceTypes = () => axios.get('/device-types');
122
123
/**
124
 * Add a device type
125
 * @param {Object} data
126
 *    - {string} label
127
 *    - {string} value
128
 */
129
exports.addDeviceType = data => axios.post('/device-types', data);
130
131
/**
132
 * Update a device type
133
 * @param {string} deviceTypeId
134
 * @param {Object} data
135
 *    - {string} label
136
 *    - {string} value
137
 */
138
exports.updateDeviceType = (deviceTypeId, data) => axios.put(`/device-types/${deviceTypeId}`, data);
139
140
/**
141
 * Remove a device type
142
 * @param {string} deviceTypeId
143
 */
144
exports.removeDeviceType = deviceTypeId => axios.delete(`/device-types/${deviceTypeId}`);
145